package cn.car.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class PageController {

    @RequestMapping("/stream/{cameraCode}")
    public String stream(Model model, @PathVariable String cameraCode
            , @RequestParam(value = "starttime", required = false) String startTime
            , @RequestParam(value = "endtime", required = false) String endTime
    ) {
        final StringBuilder sb = new StringBuilder();
        sb.append("/api/startStream/").append(cameraCode).append("?debug=true");
        if (startTime != null) {
            sb.append("&starttime=").append(startTime);
        }
        if (endTime != null) {
            sb.append("&endtime=").append(endTime);
        }
        model.addAttribute("videoUrl", sb.toString());
        return "stream";
    }

}
